<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="姓名" prop="curriculaVaribleName">
          <el-input
            v-model="queryParams.curriculaVaribleName"
            placeholder="请输入课程名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="学号" prop="curriculaVaribleAdd">
          <el-input
            v-model="queryParams.curriculaVaribleAdd"
            placeholder="请输入学号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="选课ID" align="center" prop="curriculaVaribleId" />
        <el-table-column label="选课名称" align="center" prop="curriculaVaribleName" />
        <el-table-column label="学分" align="center" prop="curriculaVaribleNumber" />
        <el-table-column label="上课教室" align="center" prop="curriculaVaribleAdd" />
        <el-table-column label="专业" align="center" prop="curriculaVaribleMajor" />
        <el-table-column label="报名人数" align="center" prop="curriculaVaribleStudentNum" />
        <el-table-column label="最大报名人数" align="center" prop="curriculaVaribleMax" />
        <el-table-column label="开课时间" align="center" prop="curriculaVaribleDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.curriculaVaribleDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="老师" align="center" prop="teacherName" />
        <el-table-column label="状态" align="center" prop="typeMsg" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['student:student:edit']"
            >添加课程</el-button>
            
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
     
    </div>
  </template>
  
  <script>
  import { listStudent, getStudent, delStudent, addStudent, updateStudent } from "@/api/student/selClass";
  
  export default {
    name: "Student",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // (注册)学生信息表格数据
        studentList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          studentName: null,
          studentNumber: null,
          studentSex: null,
          studentAdd: null,
          studentDate: null,
          studentMajor: null,
          studentPhone: null,
          allStudentId: null,
          studentBy1: null,
          studentBy2: null,
          studentBy3: null,
          studentHeadImage: null,
          studentPassword: null,
          teacherId: null,
          typeId: null,
          userId: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询(注册)学生信息列表 */
      getList() {
        this.loading = true;
        listStudent(this.queryParams).then(response => {
          this.studentList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          studentId: null,
          studentName: null,
          studentNumber: null,
          studentSex: null,
          studentAdd: null,
          studentDate: null,
          studentMajor: null,
          studentPhone: null,
          allStudentId: null,
          studentBy1: null,
          studentBy2: null,
          studentBy3: null,
          studentHeadImage: null,
          studentPassword: null,
          teacherId: null,
          typeId: null,
          userId: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.studentId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加(注册)学生信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        getStudent(row).then(response => {
          this.$modal.msgSuccess("添加成功");
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.studentId != null) {
              updateStudent(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addStudent(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const studentIds = row.studentId || this.ids;
        this.$modal.confirm('是否确认删除(注册)学生信息编号为"' + studentIds + '"的数据项？').then(function() {
          return delStudent(studentIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('student/student/export', {
          ...this.queryParams
        }, `student_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  